﻿using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace NFox.Pyeditor.Types
{
    public class TypeBase : ICompletionData, IComparable<TypeBase>
    {


        public virtual int ImageIndex { get; }

        Dictionary<int, ImageSource> _images = new Dictionary<int, ImageSource>();

        public ImageSource Image
        {
            get
            {
                if (!_images.ContainsKey(ImageIndex))
                {
                    _images[ImageIndex] =
                        new BitmapImage(new Uri($"pack://application:,,,/NFox.Pyeditor;component/Images/type{ImageIndex}.png"));
                }
                return _images[ImageIndex];
            }
        }

        // Use this property if you want to show a fancy UIElement in the drop down list.
        public object Content
        {
            get { return Text; }
        }

        public virtual string ToolTipTitle { get; }

        public virtual string ToolTipText { get; }

        public object Description
        {
            get { return $"{ToolTipTitle}\n{ToolTipText}"; }
        }

        public double Priority { get { return 0; } }

        public string Text { get; protected set; }

        public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            textArea.Document.Replace(completionSegment, Text);
        }

        public override string ToString()
        {
            return Text;
        }

        public int CompareTo(TypeBase other)
        {

            if (Text[0] == '_')
            {
                if (other.Text[0] == '_')
                    return Text.CompareTo(other.Text);
                else
                    return 1;
            }
            else
            {
                if (other.Text[0] == '_')
                    return -1;
                else
                    return Text.CompareTo(other.Text);
            }
        }

    }

    public class Statement : TypeBase
    {

        public override string ToolTipTitle { get { return $"{Text}语句"; } }
        public override string ToolTipText { get { return $"输入?{Text}以获取更多信息"; } }
        public override int ImageIndex { get { return 0; } }

        public Statement(string text)
        {
            Text = text;
        }

    }



}
